﻿CREATE PROCEDURE [dbo].[uspt_ip_create_or_update_client]
    @id VARCHAR(64),
    @secret VARCHAR(64),
    @callback_uri VARCHAR(128)
AS
    IF NOT EXISTS (SELECT 1 FROM tt_ip_client WHERE [id] = @id)
    BEGIN
        INSERT tt_ip_client([id], [secret], [callback_uri])
        VALUES (@id, @secret, @callback_uri)
    END
    ELSE
    BEGIN
        UPDATE tt_ip_client SET [secret] = @secret, [callback_uri] = @callback_uri
        WHERE [id] = @id AND ([secret] <> @secret OR [callback_uri] <> @callback_uri)
    END
RETURN 0
